package com.mofang.powerdekorhelper.adapter;

import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.support.v7.widget.RecyclerView;
import android.widget.TextView;

import com.mofang.powerdekorhelper.R;
import com.mofang.powerdekorhelper.base.recycleview.BaseRecycleViewAdapter;
import com.mofang.powerdekorhelper.base.recycleview.BaseViewHolder;
import com.mofang.powerdekorhelper.model.ArticleComment;
import com.mofang.powerdekorhelper.witget.FullyLinearLayoutManager;

import java.util.List;

/**
 * Created by luofei on 2017/5/23 0023.
 */

public class ArticleCommentAdapter extends BaseRecycleViewAdapter {

    //IReplay iReplay;

    public ArticleCommentAdapter(List<?> data, Context mContext, int layoutId) {
        super(data, mContext, layoutId);
        //iReplay = (IReplay) mContext;
    }

    @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
    @Override
    protected <T> void convert(BaseViewHolder holder, final T bean, int position) {

        final ArticleComment.Data data = (ArticleComment.Data) bean;

        holder.setText(R.id.article_comment_name, data.getCustomer_name());
        holder.setText(R.id.article_comment_time, data.getCreate_time());
        holder.setText(R.id.video_comment_content, data.getContent());
        holder.setText(R.id.article_comment_like, data.getLike_num() + "");
        TextView textView = (TextView) holder.itemView.findViewById(R.id.article_comment_like);

        CommentReplyAdapter adapter = new CommentReplyAdapter(data.getReplies(), mContext, R.layout.article_reply_item_layout);

        RecyclerView replyRecycle = (RecyclerView) holder.itemView.findViewById(R.id.video_comment_reply_list);

        replyRecycle.setLayoutManager(new FullyLinearLayoutManager(mContext) {
            @Override
            public boolean canScrollVertically() {
                return false;
            }
        });

        replyRecycle.setAdapter(adapter);

        holder.itemView.setTag(data);
    }


    class CommentReplyAdapter extends BaseRecycleViewAdapter {

        @Override
        protected <T> void convert(BaseViewHolder holder, T bean, int position) {

            ArticleComment.Replies reply = (ArticleComment.Replies) bean;

            holder.setText(R.id.article_reply_name1, reply.getCustomer_name());

            holder.setText(R.id.article_reply_name2, reply.getParent_cus_name());

            holder.setText(R.id.article_reply_content, reply.getContent());

            holder.itemView.setTag(reply);

        }

        public CommentReplyAdapter(List<?> data, Context mContext, int layoutId) {
            super(data, mContext, layoutId);
        }
    }
}
